package com.ljy.controller.admin;

import com.ljy.dto.GoodsDTO;
import com.ljy.dto.GoodsPageDTO;
import com.ljy.entity.Goods;
import com.ljy.mapper.GoodsMapper;
import com.ljy.result.PageResult;
import com.ljy.service.GoodsService;
import com.ljy.result.Result;
import com.ljy.vo.GoodsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/goods")
@Slf4j
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    @Autowired
    GoodsMapper goodsMapper;


    @PostMapping("/add")
    public Result addGoods(@RequestBody GoodsDTO dto){
        goodsService.addGoods(dto);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult<GoodsVO>> page(GoodsPageDTO dto){
        PageResult<GoodsVO> pageResult= goodsService.select(dto);
        log.info("分页查询"+pageResult);
        return Result.success(pageResult);
    }
    @GetMapping("/{id}")
    public Result<Goods> selectById(@PathVariable Integer id){
        Goods goods = goodsService.selectById(id);
        return Result.success(goods);
    }
    @PostMapping("/modify")
    public Result modifyGoods(@RequestBody GoodsDTO dto){
        goodsService.modifyGoods(dto);
        return Result.success();
    }
    @DeleteMapping
    public Result batchDelete(@RequestParam List<Integer>ids){
        goodsService.batchDelete(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Short status,Integer id){
        goodsService.changeStatus(status,id);
        return Result.success();
    }
}
